
let mps = {
	m: 'margin',
	p: 'padding',
	l: '-left',
	t: '-top',
	b: '-bottom',
	r: '-right'
}

let Re = /([pm])([xytlbr]|lt|tb|rt|rb)?(\d+)/g

const mp = (str)=>{
	let arrClass = str.match(Re)
	if (arrClass === null) return ''
	return arrClass.join('\n').replace(Re, (...args)=>{
		let [a,b,c,d] = args
		if (/(lt|lb|rt|rb)/.test(c)) {
			let value = {t:0, r:0, b:0, l:0}
			value[c[0]] = value[c[1]] = d
			value = Object.values(value).join('px ')+'px'
			return `.${a}{${mps[b]}:${value};}`
		}else if(/(x|y)/.test(c)){
			c = c == 'x' ? `0 ${d}px` : `${d}px 0`
			return `.${a}{${mps[b]}:${c};}`
		} else{
			let suffix = c ? mps[c] : ''
			return `.${a}{${mps[b]}${suffix}:${d}px;}`
		}
	})
}

module.exports = mp